package com.example.demo;

import com.example.demo.model.ChatRequest;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import jakarta.annotation.Resource;

@RestController
@RequestMapping("/api/chat")
public class ChatController {
    @Resource
    private ChatClient chatClient;


    /**
     * 处理聊天请求，使用AI和MCP工具进行响应
     *
     * @param request 聊天请求
     * @return 包含AI回复的响应
     */
    @PostMapping
    public String chat(@RequestBody ChatRequest request) {

        String userMessage = request.getMessage();

        return chatClient.prompt().user(userMessage).call().content();

    }

}
